﻿namespace MDXStudio.MdSchema
{
    using System;
    using System.Data;

    internal class MdProperty : IMdObject
    {
        private string mAttributeHierarchyName;
        private eRelationCardinality mCardinality;
        private int mContentType;
        private string mCubeName;
        private eDataType mDataType;
        private string mDescription;
        private string mDimensionUniqueName;
        private string mHierarchyUniqueName;
        private bool mIsVisible;
        private string mLevelUniqueName;
        private int mOrigin;
        private string mPropertyCaption;
        private string mPropertyName;
        private ePropertyType mPropertyType;

        public MdProperty(DataRow pRow)
        {
            this.mCubeName = (string) pRow["CUBE_NAME"];
            this.mDimensionUniqueName = (string) pRow["DIMENSION_UNIQUE_NAME"];
            this.mHierarchyUniqueName = (string) pRow["HIERARCHY_UNIQUE_NAME"];
            this.mLevelUniqueName = (string) pRow["LEVEL_UNIQUE_NAME"];
            this.mPropertyName = (string) pRow["PROPERTY_NAME"];
            this.mPropertyCaption = (string) pRow["PROPERTY_CAPTION"];
            this.mDescription = (pRow["DESCRIPTION"] is DBNull) ? string.Empty : ((string) pRow["DESCRIPTION"]);
            this.mPropertyType = (ePropertyType) ((short) pRow["PROPERTY_TYPE"]);
            this.mDataType = (eDataType) ((ushort) pRow["DATA_TYPE"]);
            this.mContentType = (pRow["PROPERTY_CONTENT_TYPE"] is DBNull) ? 0 : ((short) pRow["PROPERTY_CONTENT_TYPE"]);
            this.mOrigin = (ushort) pRow["PROPERTY_ORIGIN"];
            this.mAttributeHierarchyName = (pRow["PROPERTY_ATTRIBUTE_HIERARCHY_NAME"] is DBNull) ? string.Empty : ((string) pRow["PROPERTY_ATTRIBUTE_HIERARCHY_NAME"]);
            this.mCardinality = (((pRow["PROPERTY_CARDINALITY"] is DBNull) ? string.Empty : ((string) pRow["PROPERTY_CARDINALITY"])) == "MANY") ? eRelationCardinality.Many : eRelationCardinality.One;
            this.mIsVisible = (bool) pRow["PROPERTY_IS_VISIBLE"];
        }

        public MdProperty(string pCubeName, string pDimensionUniqueName, string pHierarchyUniqueName, string pLevelUniqueName, string pName, string pCaption, string pDescription, ePropertyType pPropertyType, int pDataType, int pContentType, int pOrigin, string pAttributeHierarchyName, eRelationCardinality pCardinality, bool pIsVisible)
        {
            this.mCubeName = pCubeName;
            this.mDimensionUniqueName = pDimensionUniqueName;
            this.mHierarchyUniqueName = pHierarchyUniqueName;
            this.mLevelUniqueName = pLevelUniqueName;
            this.mPropertyName = pName;
            this.mPropertyCaption = pCaption;
            this.mDescription = pDescription;
            this.mPropertyType = pPropertyType;
            this.mDataType = (eDataType) pDataType;
            this.mContentType = pContentType;
            this.mOrigin = pOrigin;
            this.mAttributeHierarchyName = pAttributeHierarchyName;
            this.mCardinality = pCardinality;
            this.mIsVisible = pIsVisible;
        }

        public MdProperty SetName(string pName)
        {
            return new MdProperty(this.mCubeName, this.mDimensionUniqueName, this.mHierarchyUniqueName, this.mLevelUniqueName, pName, pName, string.Empty, ePropertyType.MDPROP_SYSTEM, 130, this.mContentType, this.mOrigin, this.mAttributeHierarchyName, this.mCardinality, this.mIsVisible);
        }

        public override string ToString()
        {
            return this.mPropertyCaption;
        }

        public string AttributeHierarchyName
        {
            get
            {
                return this.mAttributeHierarchyName;
            }
        }

        public string Caption
        {
            get
            {
                return this.mPropertyCaption;
            }
        }

        public eRelationCardinality Cardinality
        {
            get
            {
                return this.mCardinality;
            }
        }

        public int ContentType
        {
            get
            {
                return this.mContentType;
            }
        }

        public string CubeName
        {
            get
            {
                return this.mCubeName;
            }
        }

        public eDataType DataType
        {
            get
            {
                return this.mDataType;
            }
        }

        public string Description
        {
            get
            {
                return this.mDescription;
            }
        }

        public string DimensionUniqueName
        {
            get
            {
                return this.mDimensionUniqueName;
            }
        }

        public string HierarchyUniqueName
        {
            get
            {
                return this.mHierarchyUniqueName;
            }
        }

        public bool IsVisible
        {
            get
            {
                return this.mIsVisible;
            }
        }

        public string LevelUniqueName
        {
            get
            {
                return this.mLevelUniqueName;
            }
        }

        public string Name
        {
            get
            {
                return this.mPropertyName;
            }
        }

        public int Origin
        {
            get
            {
                return this.mOrigin;
            }
        }

        public ePropertyType PropertyType
        {
            get
            {
                return this.mPropertyType;
            }
        }

        public string UniqueName
        {
            get
            {
                return this.mPropertyName;
            }
        }
    }
}

